﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BussinessLib;
using Global;

public partial class Restaurant_ManageRestaurant : System.Web.UI.Page
{
    
      

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            Button1.Enabled = false;
            this.Button2.Enabled = false;

            RestaurantManager ResManager = new RestaurantManager();
            DataTable ReturnSet = ResManager.SearchRestauarant("", "");
            this.GridView1.DataSource = ReturnSet;
            this.GridView1.DataBind();
        }
    }
    protected void ButAdd_Click(object sender, EventArgs e)
    {
       // Response.Redirect("hhh.aspx?auth=" + mythear);
        Session["flag"] = "add";
        Response.Redirect("AddRestaurant.aspx");
    }
    protected void ButUpdate_Click(object sender, EventArgs e)
    {


        Session["flag"] = "edit";
        //string k = Session["name"].ToString();
        Response.Redirect("AddRestaurant.aspx");

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.Button1.Enabled = true;

        this.BtnUpdate.Enabled = true;
        this.Button2.Enabled = true;
        this.BtnDel.Enabled = true;
        GridViewRow selectRow = this.GridView1.SelectedRow;

        Session["name"] = selectRow.Cells[0].Text.ToString().Trim();  
         Session["address"] = selectRow.Cells[1].Text.ToString().Trim(); 
         Session["tel"] = selectRow.Cells[2].Text.ToString().Trim(); 
         Session["tablenum"] = int.Parse(selectRow.Cells[3].Text.ToString().Trim()); 
          Session["min"] = int.Parse(selectRow.Cells[4].Text.ToString().Trim()); 
          Session["max"] = int.Parse(selectRow.Cells[5].Text.ToString().Trim()); 
           Session["city"] = selectRow.Cells[6].Text.ToString().Trim();
           Session["desc"] = selectRow.Cells[7].Text.ToString().Trim();

          Session["id"] = int.Parse(selectRow.Cells[8].Text.ToString().Trim());

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }
    protected void BtnDel_Click(object sender, EventArgs e)
    {
     //   RestaurantManager ResManager = new RestaurantManager();

        CreateManager Creator = new CreateManager();
        BaseManager ResManager = Creator.GetManager(1);


        Restaurant res = new Restaurant();


        res.SetID(int.Parse(Session["id"].ToString()));
       // ResManager.DeleteRestaurant(res);
        ResManager.DeleteObject(res);


        RestaurantManager ResManagerTrue = (RestaurantManager)ResManager;
        DataTable ReturnSet = ResManagerTrue.SearchRestauarant("", "");
        this.GridView1.DataSource = ReturnSet;
        this.GridView1.DataBind();



    }
    protected void BtnSearch_Click(object sender, EventArgs e)
    {

    }
    //餐位管理
    protected void Button1_Click(object sender, EventArgs e)
    {
        

        Session["resid"] = Session["id"];
        Response.Redirect(@"~\seat\managetable.aspx");
         


    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Session["resid"] = Session["id"];
        Response.Redirect(@"~\Restaurant\OrderInfo.aspx");

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Redirect(@"~\usermanagement\admin.aspx");

    }
}
